﻿Public Class FrmServiceNotRunning
    Public Event EVENT_SERVICERUNNING()
    Dim Controller As ServiceProcess.ServiceController
    Private Cancel_Closing As Boolean

    Private Sub CmdShutDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdShutDown.Click
        Dim answer As MsgBoxResult
        answer = MsgBox("Are you sure that you want to close Bandyt BITS?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Close Bandyt BITS?")
        DialogResult = Windows.Forms.DialogResult.Cancel

    End Sub

    Private Sub TimCheckService_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimCheckService.Tick
        If Me.Visible Then
            Controller.Refresh()
            If Controller.Status = ServiceProcess.ServiceControllerStatus.Running Then
                RaiseEvent EVENT_SERVICERUNNING()
                TimCheckService.Stop()
                Cancel_Closing = False
                Me.Close()
            End If
        End If
    End Sub

    Private Sub FrmServiceNotRunning_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Cancel_Closing Then
            e.Cancel = True
        Else
            e.Cancel = False
            Cancel_Closing = True
        End If
    End Sub

    Private Sub FrmServiceNotRunning_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Controller = New ServiceProcess.ServiceController
        Controller.ServiceName = "BITS"
        Cancel_Closing = True
        'TimCheckService.Stop()
    End Sub
End Class